<?php
namespace Tbf\Bundle\RouteBundle;
use Tbf\Bundle\RouteBundle\Exclude\ExcludeInterface;
use Tbf\Bundle\RouteBundle\Matcher\MatcherInterface;

class RouteConfig {
    /**
     * @var ExcludeInterface[]
     */
    protected $exclude_routes = array();
    /**
     * @var MatcherInterface[]
     */
    protected $match_routes=array();

    /**
     * @param ExcludeInterface[] $exclude_routes
     */
    public function setExcludeRoutes($exclude_routes)
    {
        $this->exclude_routes = $exclude_routes;
    }

    /**
     * @return ExcludeInterface[]
     */
    public function getExcludeRoutes()
    {
        return $this->exclude_routes;
    }

    public function addExcludeRoute(ExcludeInterface $exclude){
        $this->exclude_routes[] = $exclude;
    }

    /**
     * @param MatcherInterface[] $match_routes
     */
    public function setMatchRoutes($match_routes)
    {
        $this->match_routes = $match_routes;
    }

    /**
     * @return MatcherInterface[]
     */
    public function getMatchRoutes()
    {
        return $this->match_routes;
    }
    public function addMatchRoute(MatcherInterface $matcher){
        $this->match_routes[] = $matcher;
    }
    public function merge(RouteConfig $config){
        foreach($config->exclude_routes as $exclude){
            $this->addExcludeRoute($exclude);
        }
        foreach($config->match_routes as $match){
            $this->addMatchRoute($match);
        }
    }
    public static function newFromLoaderList(array $loader_list=array()){
        $obj = new RouteConfig();
        foreach($loader_list as $loader){
            $obj->merge($loader->getConfig());
        }
        return $obj;
    }
}